#include <stdio.h>
#include <string.h>
#include "symbolTable.h"
#include "portal.y.c"
symbolTable *head;

symbolTable* createItem() {
	symbolTable *new;
	
	new = (symbolTable*) malloc(sizeof(symbolTable));
	new->next = NULL;
	new->prev = NULL;
	return new;
}

int isEmpty(symbolTable *table){
	if(table == NULL) return 1;
	else return 0;
}

symbolTable* search(char *name) {
	symbolTable *p;
	p = head;
	while (p != NULL) {
		if (strcmp(p->name, str)) {
			return p;
		}
		p = p->next;
	}
	return NULL;
}

int isAdded(char str[64]) {
	symbolTable *p;
	p = head;
	while (p != NULL) {
		if (strcmp(p->name, str)) {
			return 1;
		}
		p = p->next;
	}
	return 0;
}

int add(symbolTable **table, char name[64] ) {
	symbolTable *new;
	if (isEmpty(*table)) {
		new = createItem();
		strcpy(new->name,name);
	}
	else {
		if (!isAdded((*table)->name)) {
			new = createItem();
			// TODO inserir valor
			(*table)->next = new;
			new->prev = *table;
			*table = new;
			return 0;
		}
	}
	return -1;
}

void TS_Insere_Tipo(char *name, int type){
	symbolTable *p;
	p = search(name);
	p->type = type;
	return p;
}

int main() {
	symbolTable *head;
	printf("Comecou");
	mainParser();
	printf("\nAcabou\n");
	return 0;
}
	

